package com.bookmanagement.mapper;

import com.bookmanagement.entity.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("select name from category where id=#{id}")
    String getCategoryById(Integer id);

    // 获取所有分类
    @Select("select * from category order by create_at desc")
    List<Category> getAllCategories();

    // 添加分类
    @Insert("insert into category(name) values(#{name})")
    void insertCategory(Category category);

    // 根据名称查询分类
    @Select("select * from category where name = #{name}")
    Category getCategoryByName(String name);
}
